Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
How can i clear "Object are not valid as React Child" Error in react-native

Parent Component--

import React from "react";
import {View,SafeAreaView,Text,StyleSheet} from 'react-native';
import TestComponent from "./Components/TestComponent";

const Test = () => {
    return (
            <View>
                <Text>Here are some boxes of different colours</Text>
                <TestComponent 
                    color='#2aa198'
                    name='Cyan'
                />
                <TestComponent 
                    color='#268bd2'
                    name='Blue'
                />
                <TestComponent 
                    color='#d33682'
                    name='Magenta'
                />
                <TestComponent 
                    color='#cb4b16'
                    name='Orange'
                />
            </View>
    );
};

const styles = StyleSheet.create({
        
});

export default Test;

Child Component--enter code here

import React from "react";
import {View,Text,StyleSheet} from 'react-native';

const TestComponent = ({color,name}) => {
    const colour = {
        backgroundColor:color,
    };

    return (
        <View style={colour}>
            <Text>{name}{colour}</Text>
        </View>
    )
};

const styles = StyleSheet.create({
    mH:{
        marginHorizontal:10
    },
    mV:{
        marginVertical:5
    },
    height:{
        height:30
    }
    
});

export default TestComponent;

When I try to use color prop as object in view in child property I'm getting error as "Objects are not valid as React child(found Object with keys {backgroundColor} and I also tried using colour.backgroundColor as well and still it is not working and I'm getting same error

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You pass an object as a child to the Text component. I am assuming that you want to show the color code as a text inside the text component. Instead of passing the object colour, just pass color.

const TestComponent = ({color,name}) => {
    const colour = {
        backgroundColor:color,
    };

    return (
        <View style={colour}>
            <Text>{name}{color}</Text>
        </View>
    )
};

Here is a working snack.

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda